﻿using IntelligentGateway.Data;
using IntelligentGateway.Model;
using IntelligentGateway.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IntelligentGateway.Services
{
    public class UserServices
    {
        public ResponseMessage UpdatePassword(string strUser, string strOldPassword, string strNewPassword)
        {
            ResponseMessage message = new ResponseMessage();
            UserDA userDA = new UserDA();
            string pwdAfter = SecureTools.Encrypt(strOldPassword);
            UserInfo user = userDA.LoginProc(strUser, pwdAfter);
            if (user == null)
            {
                message.errcode = 1;
                message.errmsg = "原密码不正确!";
                return message;
            }            
            pwdAfter = SecureTools.Encrypt(strNewPassword);
            if (userDA.UpdatePassword(strUser, pwdAfter))
            {
                message.errcode = 0;
                message.data = "修改成功!";
            }
            else
            {
                message.errcode = 1;
                message.errmsg = "修改错误!";
            }
            return message;
        }
        public ResponseMessage ResetPassword(string strUser)
        {
            ResponseMessage message = new ResponseMessage();
            UserDA da = new UserDA();
            string pwdAfter = SecureTools.Encrypt("123456");
            if (da.UpdatePassword(strUser, pwdAfter))
            {
                message.errcode = 0;
                message.data = "修改成功!";
            }
            else
            {
                message.errcode = 1;
                message.errmsg = "修改错误!";
            }
            return message;
        }
    }
}
